import { FakeApi, random } from '@wowon/utils';
import { getCurrentUser } from '../../auth-center';

const answer = `
### 更新内容

- 💄 统一 Modal、Drawer、notification 和 Tour 关闭按钮的样式，并增大 Modal 和 Drawer 关闭按钮的交互区域使其更容易点击。#47909
- 🐞 修复 Badge 和文本元素在 Space 下排版不对齐的问题。#47908
- 💄 修复 Upload 列表行动点换行的问题。#47898
- 🐞 修复 Typography 配置的 ellipsis.symbol 超出单行高度时，省略行数不正确的问题。#47889
- 🐞 修复 DatePicker 配置自定义 controlHeight 时展示高度不正确的问题。#47874
- 🐞 修复 DatePicker 设置 multiple 多选换行时行与行之间没有间隙的问题。#47821
- 💄 调深 Empty 文本色彩使其更清晰可读一些。#47268 @evgmol
`;

const initData = Array.from({ length: random(20, 40) }).map((_, i) => ({
  qid: `${i + 1}`,
  type: random(['help', 'question']),
  question: random(['新用户怎么在平台注册账号？', '用户在哪里操作注销账号？', '为什么我看不到角色管理的新增按钮？']),
  answer,
}));

export const helpList = new FakeApi(initData, {
  key: 'qid',
  queryType: {
    qid: 'is',
    type: 'is',
    question: 'like',
  },
});

export default {
  'GET /mock/help/query': async (req, res) => {
    const currentUser = getCurrentUser(req);
    if (!currentUser) {
      res.statusCode = 401;
      res.json({ code: '-1', message: '权限不足' });
      return;
    }
    const result = await helpList.query(req.query);
    res.json(result);
  },
  'POST /mock/help/create': async (req, res) => {
    const currentUser = getCurrentUser(req);
    if (!currentUser) {
      res.statusCode = 401;
      res.json({ code: '-1', message: '权限不足' });
      return;
    }
    const result = await helpList.create(req.body);
    res.json(result);
  },
  'POST /mock/help/update': async (req, res) => {
    const currentUser = getCurrentUser(req);
    if (!currentUser) {
      res.statusCode = 401;
      res.json({ code: '-1', message: '权限不足' });
      return;
    }
    const result = await helpList.update(req.body);
    res.json(result);
  },
  'POST /mock/help/remove': async (req, res) => {
    const currentUser = getCurrentUser(req);
    if (!currentUser) {
      res.statusCode = 401;
      res.json({ code: '-1', message: '权限不足' });
      return;
    }
    const result = await helpList.remove(req.body);
    res.json(result);
  },
};
